<template>
    <div>
        <ResourcePool />
        <div class="title">
            <img v-show="$store.state.TitleName && $store.state.TitleName !== '文本'" style="position: absolute;left: 13px;top: 7px;cursor: pointer;" src="../assets/img/icon_返回.png" alt="" @click="backPool">
            {{$store.state.TitleName?$store.state.TitleName:$store.state.PoolName}}
        </div>
        <ResourcePoolSort />
        <div @dragstart="handleDragStart" class="component-list" v-if="$store.state.TitleName">
            <div v-for="(item, index) in componentList.filter(item => item.label == $store.state.TitleName)" :key="index" class="list" draggable :data-index="index">
                <img draggable="false" :src="item.icon" alt="">
                <span style="font-size: 10px;">{{ item.name }}</span>
            </div>
        </div>
    </div>
</template>

<script>
import componentList from '@/custom-component/component-list'
import ResourcePool from './ResourcePool.vue'
import ResourcePoolSort from './ResourcePoolSort.vue'

export default {
    data() {
        return {
            componentList,
        }
    },
    components: {
        ResourcePool,
        ResourcePoolSort,
    },
    methods: {
        handleDragStart(e) {
            e.dataTransfer.setData('index', e.target.dataset.index)
        },
        backPool() {
            this.$store.commit('setTitleName', '')
        },
    },
    mounted() {},
}
</script>

<style lang="scss" scoped>
.title {
    position: absolute;
    right: 12px;
    top: 10px;
    text-align: center;
    width: 162px;
    height: 32px;
    background: #273045;
    border-radius: 4px;
    opacity: 0.7;
    color: #ffffff;
    line-height: 32px;
}
.component-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 10px;
    width: 81%;
    position: absolute;
    right: 0;
    top: 45px;
    .list {
        width: 45%;
        cursor: grab;
        margin-bottom: 15px;
        text-align: center;
        color: #333;
        padding: 2px 5px;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 75px;
        flex-direction: column;
        background: #d8d8d81a;
        border-radius: 4px;
        span {
            color: #ffffff40;
        }
        &:hover {
            background: #5bc4d633;
        }
        &:active {
            cursor: grabbing;
        }

        .iconfont {
            margin-right: 4px;
            font-size: 20px;
        }

        .icon-wenben,
        .icon-tupian {
            font-size: 18px;
        }
    }
}
</style>